package com.accompany.common.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class UtilsTime {
    public static String getDatePoor(Date endDate, Date nowDate) {
        long nd = 1000 * 24 * 60 * 60;
        long nh = 1000 * 60 * 60;
        long nm = 1000 * 60;
        // long ns = 1000;
        // 获得两个时间的毫秒时间差异
        long diff = endDate.getTime() - nowDate.getTime();
        // 计算差多少天
        long day = diff / nd;
        // 计算差多少小时
        long hour = diff % nd / nh;
        // 计算差多少分钟
        long min = diff % nd % nh / nm;
        // 计算差多少秒//输出结果
        // long sec = diff % nd % nh % nm / ns;
        return day + "天" + hour + "小时" + min + "分钟";
    }

    /**
     * 计算两个时间相差多少个小时
     * @param endDate
     * @param nowDate
     * @return
     */
    public static long getDateSubtractHour(Date endDate, Date nowDate) {
        long nd = 1000  * 60 * 60;
        // 获得两个时间的毫秒时间差异
        long diff = endDate.getTime() - nowDate.getTime();;
        // 计算差多少小时
        long hour = diff / nd;
        return hour;
    }

    /**
     * 判断工人存在是否大于12小时
     * @param time
     * @return
     * @throws ParseException
     */
    public static boolean workerIs12(String time) throws ParseException {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = simpleDateFormat.parse(time);
        long hour = UtilsTime.getDateSubtractHour(new Date(),date);
        return hour>=12?true:false;
    }

    public static String getTime(){
       return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
    }

    public static String getDayTime(){
        return new SimpleDateFormat("yyyy-MM-dd").format(new Date());
    }

    public static String getMonthTime(){
        return new SimpleDateFormat("yyyy-MM").format(new Date());
    }

}
